import axios from 'axios';
import {
    Loading
} from 'element-ui';
var instance = axios.create({
    baseURL: 'https://www.liulongbin.top:8888/api/private/v1/',
    timeout: 6000
})
// 请求拦截   发送请求之前自动执行
var loadingInstance;

instance.interceptors.request.use(
    config => {
        loadingInstance = Loading.service({
            fullscreen: true
        });
        var token = sessionStorage.getItem('token');
        var users = JSON.parse(sessionStorage.getItem('users')) || {};
        if (users.token) {
            config.headers.authorization = users.token;
            return config;
        } else {
            return config;
        }
    },
    err => {

    }
)

//  响应拦截   拿到数据后但是没有渲染之前执行
instance.interceptors.response.use(response => {
    // console.log(response)
    loadingInstance.close();
    return response;
});

// 导出
export default instance;